﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Esint.Common.Data;
using Esint.JudicialAuction.Model;
using Esint.Common.Model;
using System.Data.SqlClient;
using Esint.JudicialAuction.IDAL;
namespace Esint.JudicialAuction.SqlDAL
{
    /// <summary>
    /// 模块名称：公共方法数据访问层
    /// 作    者：阎宝成
    /// 生成日期：2011年08月31日
    /// 修改说明：
    /// </summary>
    public partial class CommonData : BaseData,ICommonData
    {
        /// <summary>
        /// 获得数据库服务器当前时间
        /// </summary>
        /// <returns>数据库服务器当前时间</returns>
        public string GetNowDate()
        {
            DataQuery query = new DataQuery();
            query.SQLText = @"select getdate() as datetime";
            DataTable tabTime = ExecuteDataTable(query);
            return tabTime.Rows[0]["datetime"].ToString();

        }
        /// <summary>
        /// 数据库时间格式化为时间戳
        /// </summary>
        /// <returns></returns>
        public string GetNowDatefomat()
        {
            DataQuery query = new DataQuery();
            query.SQLText = @"select replace(replace(replace(replace(convert(varchar(120),getdate(),126),'T',''),'-',''),':',''),'.','') as datetime";
            DataTable tabTime = ExecuteDataTable(query);
            return tabTime.Rows[0]["datetime"].ToString();

        }

        public string GetNowDATEDIFFDate(string datetime)
        {
            DataQuery query = new DataQuery();
            query.SQLText = @"SELECT DATEDIFF(year,  '" + datetime + "',getdate()) datetime";
            DataTable tabTime = ExecuteDataTable(query);
            return tabTime.Rows[0]["datetime"].ToString();
        }
    }
}
